package net.csdn.business.mirror;

import lombok.extern.slf4j.Slf4j;
import net.csdn.business.adapter.AdapterService;
import net.csdn.business.common.feign.yunxiao.model.request.ImportProjectDto;
import net.csdn.business.common.feign.yunxiao.model.request.MirrorProjectDto;
import net.csdn.business.common.feign.yunxiao.model.vo.ProjectVo;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;

@ActiveProfiles("dev")
@RunWith(SpringRunner.class)
@SpringBootTest(properties = {"spring.profiles.active=dev", "logging.file.path=/Users/yanlp/IdeaProjects/atomgit/openatom-mirror/logs"})
@Slf4j
public class AdapterServiceTest {
    @Autowired
    private AdapterService adapterService;

    @Test
    public void getProjectById() {
        ProjectVo projectVo = adapterService.getProjectById(27152L);
        log.info("projectVo: {}", projectVo);
    }


    @Test
    public void importProject() {
        ImportProjectDto dto = new ImportProjectDto();
        dto.setName("vue");
        dto.setPath("vue");
//        dto.setNamespace_id(3385L);
        dto.setVisibility_level(20);
        dto.setImport_url("https://github.com/vuejs/vue.git");
        dto.setDescription("vue description");
        dto.setSync(false);
        dto.setCreate_parent_path(false);
        dto.setExtern_uid("62c3db3aca5651f6b4c31eb7");
        // name_space targetId
        dto.setOrganization_id("63bbe7d59d53c71fb790ac70");
        dto.setTarget_org_id("63bbe7d59d53c71fb790ac70");
        adapterService.importProject(dto);
    }

    @Test
    public void mirrorProject() {
        MirrorProjectDto dto = new MirrorProjectDto();
        dto.setRepositoryId(32866L);
//        dto.setExtern_uid("62c3db3aca5651f6b4c31eb7");
        // name_space targetId
//        dto.setOrganization_id("63bbe7d59d53c71fb790ac70");
        dto.setExtern_uid("62c3db3aca5651f6b4c31eb7");
        dto.setOrganization_id("63bbe7d59d53c71fb790ac70");
        adapterService.mirror(dto);
    }

    @Test
    public void mirrorProjectV2() {
        MirrorProjectDto dto = new MirrorProjectDto();
        dto.setRepositoryId(32860L);
//        dto.setExtern_uid("62c3db3aca5651f6b4c31eb7");
        // name_space targetId
//        dto.setOrganization_id("63bbe7d59d53c71fb790ac70");
        dto.setExtern_uid("62bc36998d903b8944067292");
        dto.setOrganization_id("6311ec658cfdd5a134b25fd3");
        dto.setAccount("Whoops");
        dto.setToken("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");
        adapterService.mirror(dto);
    }

    @Test
    public void importProjectGitee() {
        ImportProjectDto dto = new ImportProjectDto();
        dto.setName("test1");
        dto.setPath("test1");
        dto.setVisibility_level(0);
        dto.setImport_url("https://gitee.com/yanlinpu/test1.git");
        dto.setDescription("test");
        dto.setSync(false);
        dto.setCreate_parent_path(false);

        dto.setExtern_uid("63f81a5a3f3ca3f7c2ba01d9");
        dto.setOrganization_id("63f81a5a3f3ca3f7c2ba01d9");
        dto.setTarget_org_id("63f81a5a3f3ca3f7c2ba01d9");
        // gitee import_acoount 必须为gitee的account
        // dto.setImport_account("leige");
        dto.setImport_account("yanlinpu");
        dto.setImport_token("e0013a185e13e6af610e46ffa4d57da0");
        adapterService.importProject(dto);
    }
}
